using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Tomahawk.Runtime.Rendering.Interfaces;
using Microsoft.Xna.Framework.Content;

namespace Tomahawk.Runtime.Rendering.Objects
{
    /// <summary>
    /// Basic renderable 3D Model.
    /// IMPORTANT: This will be replaced in the future with a renderable entity compatible with the material framework
    /// </summary>
    public class BasicMesh : Entity, IRenderable
    {
        protected Model meshModel;

        /// <summary>
        /// Allow access to the model itself
        /// </summary>
        public Model Model
        {
            get { return this.meshModel; }
        }

        private string modelAsset = "";

        public BasicMesh(string ModelAsset)
        {
            this.modelAsset = ModelAsset;
        }

        protected override bool OnLoad(GraphicsDevice graphics, ContentManager contentManager)
        {
            //load the mesh
            this.meshModel = contentManager.Load<Model>(modelAsset);

            //
            return true;
        }


        #region IRenderable Members

        public void Render(ref Matrix worldMatrix, GraphicsDevice myDevice)
        {

            foreach (ModelMesh mesh in this.meshModel.Meshes)
            {

                foreach (Effect effect in mesh.Effects)
                {
                    //Aply the engine parameters
                    //Engine.Instance.ShaderManager.AplyEngineShaderParameters(worldMatrix, effect);
                }

                mesh.Draw();

            }

        }

        #endregion

    }

}